<?

/**
* local collection functions of tocmenu_611
*
* @author Adesanto Asman
* @version 1.0
* @license Free
* @copyright Copyright (c)2007, Adesanto Asman
* @package CLFetchers
*
*/

/**
* @package CLFetchers
*
*/
class CLFetchers{

  /**
   * ser number list
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $srcDb
   * @param integer   $nData
   * @param array     $lstData
   */
  function subDtlSerNumber(&$Db,
                            $jobId,
                            $srcDb,
                           &$nData,
                           &$lstData){

    $query	= "SELECT *
               FROM ".$srcDb."
               WHERE	JOB_ID='".$jobId."' ";

    $Db->execFetchQuery($query,
                        $nData,
                        $lstData);
  }

  /**
   * is warehouse has this SN
   *
   * @param Database  $Db
   * @param string    $warehouse
   * @param string    $serNumber
   * @param string    $srcDb
   * @param boolean   $retSN
   */
  function fetchWhsHasSn(&$Db,
                         &$warehouse,
                         &$serNumber,
                          $srcDb,
                         &$retSN){

    $query	= "SELECT *
               FROM ".$srcDb."
               WHERE	SN='".$serNumber."'
                      AND WAREHOUSE='".$warehouse."' ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    if($nrows > 0){

      $retSN = true;
    }else{

      $retSN = false;
    }
  }

  /**
   * list of warehouse's model
   *
   * @param Database  $Db
   * @param Composer  $SourceDb
   * @param array     $lstModel
   */
  function fetchLstWhsModel(&$Db,
                            &$SourceDb,
                            &$lstModel){

    $query	= "SELECT W.*,
                      M.MODEL,
                      M.UNIT
               FROM ".$SourceDb->fetchValue("srcDbWarehouse")." W,
                    ".$SourceDb->fetchValue("srcDbModel")."     M
               WHERE  W.MODEL_ID=M.MODEL_ID
               ORDER BY W.MODEL_ID ASC";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    CLocal::filterZeroBalance($result);

    $lstModel = $result["MODEL"];
  }

  /**
   * data header
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param Composer  $SourceDb
   * @param integer   $nHeader
   * @param array     $lstHeader
   */
  function fetchLstDataHeader(&$Db,
                              &$jobId,
                              &$SourceDb,
                              &$nHeader,
                              &$lstHeader){

    $query	= "SELECT H.*,
                      M.MODEL,
                      M.UNIT
               FROM ".$SourceDb->fetchValue("srcDbHdr")."   H,
                    ".$SourceDb->fetchValue("srcDbModel")." M
               WHERE	H.JOB_ID='".$jobId."'
                      AND H.MODEL_ID=M.MODEL_ID ";

    $Db->execFetchQuery($query,
                        $nHeader,
                        $lstHeader);
  }

  /**
  * fetch the list of valid transactions
  *
  * @param  Database  $Db
  * @param  string    $condt      the condition
  * @param  Composer  $SourceDb
  * @param  string    $lstResult
  *
  */
  function fetchLstTransaction(&$Db,
                               $condt,
                               &$SourceDb,
                               &$nResult,
                               &$lstResult){

    $query  = "SELECT H.*,
                      M.MODEL
               FROM ".$SourceDb->fetchValue("srcDbHdr")."   H,
                    ".$SourceDb->fetchValue("srcDbModel")." M
               ".$condt."
                    AND H.MODEL_ID=M.MODEL_ID
               ORDER BY H.TR_DATE DESC ";

    $Db->execFetchQuery($query,
                        $nResult,
                        $lstResult);
  }
}

?>